<template>
  <div class="teamwork-container">
    <el-row :gutter="15">
      <el-col :lg="6" :md="12" :sm="24" :xl="6" :xs="24">
        <el-card shadow="hover" skeleton>
          <template #header>
            <div class="card-header">
              <span>最新更新通知</span>
            </div>
            <el-tag class="card-header-tag" type="success">历史更新</el-tag>
          </template>
          <div v-for="o in 7" :key="o" class="text item">
            <p
              style="
                height: 25px;
                padding-bottom: 10px;
                clear: both;
                border-bottom: 1px solid #f0f0f0;
              "
            >
              <e-text style="float: left">{{ o + '   这是最新消息' }}</e-text>
              <e-text style="float: right">{{ '2024/02/08' }}</e-text>
            </p>
          </div>
        </el-card>
      </el-col>
      <el-col :lg="6" :md="12" :sm="24" :xl="6" :xs="24">
        <el-card shadow="hover" skeleton>
          <template #header>
            <div class="card-header">
              <span>最新意见反馈</span>
            </div>
            <el-tag class="card-header-tag" type="success">
              进入意见反馈中心
            </el-tag>
          </template>
          <div v-for="o in 7" :key="o" class="text item">
            <p
              style="
                height: 25px;
                padding-bottom: 10px;
                clear: both;
                border-bottom: 1px solid #f0f0f0;
              "
            >
              <e-text style="float: left">{{ o + '   这是最新消息' }}</e-text>
              <e-text style="float: right">{{ '2024/02/08' }}</e-text>
            </p>
          </div>
        </el-card>
      </el-col>
      <el-col :lg="6" :md="12" :sm="24" :xl="6" :xs="24">
        <el-card shadow="hover" skeleton>
          <template #header>
            <div class="card-header">
              <span>最新意见反馈</span>
            </div>
            <el-tag class="card-header-tag" type="success">
              进入意见反馈中心
            </el-tag>
          </template>
          <div v-for="o in 7" :key="o" class="text item">
            <p
              style="
                height: 25px;
                padding-bottom: 10px;
                clear: both;
                border-bottom: 1px solid #f0f0f0;
              "
            >
              <e-text style="float: left">{{ o + '   这是最新消息' }}</e-text>
              <e-text style="float: right">{{ '2024/02/08' }}</e-text>
            </p>
          </div>
        </el-card>
      </el-col>
    </el-row>
    <edit ref="editRef" @fetch-data="fetchData" />
  </div>
</template>

<script>
  import { getList, doDelete } from '@/api/teamwork'
  import Edit from './components/TeamworkEdit'
  import { Delete, Plus, Search } from '@element-plus/icons-vue'

  export default defineComponent({
    name: 'Teamwork',
    components: { Edit },
    setup() {
      const $baseConfirm = inject('$baseConfirm')
      const $baseMessage = inject('$baseMessage')

      const state = reactive({
        editRef: null,
        list: [],
        listLoading: true,
        layout: 'total, sizes, prev, pager, next, jumper',
        total: 0,
        selectRows: '',
        queryForm: {
          TeamWorkState: 0,
          pageNo: 1,
          pageSize: 10,
          title: '',
        },
      })

      const changeTab = (e) => {
        state.queryForm.TeamWorkState = e.index
        fetchData()
      }
      const setSelectRows = (val) => {
        state.selectRows = val
      }
      const handleEdit = (row) => {
        if (row.TeamWorkID) {
          state.editRef.showEdit(row)
        } else {
          state.editRef.showEdit()
        }
      }
      const handleDelete = (row, upstate) => {
        let upname = ''
        if (upstate == 1) {
          upname = '完成'
        } else {
          upname = '退回'
        }

        if (row.TeamWorkID) {
          $baseConfirm(`你确定要${upname}当前项吗`, null, async () => {
            const { msg } = await doDelete({
              ids: row.TeamWorkID,
              upset: upstate,
            })
            $baseMessage(msg, `${upname}成功`, 'vab-hey-message-success')
            await fetchData()
          })
        } else {
          if (state.selectRows.length > 0) {
            const ids = state.selectRows.map((item) => item.TeamWorkID).join()
            $baseConfirm(`你确定要${upname}当前项吗`, null, async () => {
              const { msg } = await doDelete({ ids: ids, upset: upstate })
              $baseMessage(msg, `${upname}成功`, 'vab-hey-message-success')
              await fetchData()
            })
          } else {
            $baseMessage('未选中任何行', 'error', 'vab-hey-message-error')
          }
        }
      }
      const handleSizeChange = (val) => {
        state.queryForm.pageSize = val
        fetchData()
      }
      const handleCurrentChange = (val) => {
        state.queryForm.pageNo = val
        fetchData()
      }
      const queryData = () => {
        state.queryForm.pageNo = 1
        fetchData()
      }
      const fetchData = async () => {
        state.listLoading = true
        const {
          data: { list, total },
        } = await getList(state.queryForm)
        state.list = list
        state.total = total
        state.listLoading = false
      }
      onMounted(() => {
        // fetchData()
      })

      return {
        ...toRefs(state),
        changeTab,
        setSelectRows,
        handleEdit,
        handleDelete,
        handleSizeChange,
        handleCurrentChange,
        queryData,
        fetchData,
        Delete,
        Plus,
        Search,
      }
    },
  })
</script>

<style lang="scss" scoped>
  .teamwork-container {
    padding: 10 !important;
    background: $base-color-background !important;
  }
</style>
